package com.qf.utils;

/**
 * @author lipengg
 * @date 2021/10/26
 */

import com.qf.dao.OrderMapper;
import com.qf.pojo.po.XcOrder;
import com.qf.pojo.req.TrainOrderAndOrderDetail;
import com.qf.service.HotelService;
import com.qf.service.JqOrderService;
import com.qf.service.XcOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Component
public class ScheduTask {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    JqOrderService jqOrderService;

    @Autowired
    XcOrderService xcOrderService;

    @Autowired
    HotelService hotelService;
    @Scheduled(cron = "0 0/30 * * * ? ")
//    @Scheduled(cron = "0/5 * * * * ? ")
    @Transactional
    public void testSca() {
        List<XcOrder> all = orderMapper.findAll();
        System.out.println(all);
        List<XcOrder> noPayOrders = new ArrayList<>();
        for (XcOrder order : all) {
            if (order.getOrderStatus() == 1) {
                noPayOrders.add(order);
            }
        }
        if (noPayOrders.size() > 0) {
            //修改
                for (XcOrder xcOrder : noPayOrders) {
                    if (xcOrder.getOrderType() == 1 || xcOrder.getOrderType() == 5) {
//                    TrainOrderAndOrderDetail trainOrderAndOrderDetail = new TrainOrderAndOrderDetail();
//                    BeanUtils.copyProperties(xcOrder, TrainOrderAndOrderDetail.class);
////                    trainOrderAndOrderDetail.setXcOrderDetail(xcOrder.getXcOrderDetailList().get(0));
//                    xcOrderService.deleteorder(trainOrderAndOrderDetail);
                    }else if (xcOrder.getOrderType() == 3){
                        jqOrderService.cancelOrder(xcOrder.getOrderId());
                    }else if (xcOrder.getOrderType() == 4){
                        hotelService.checkOut(xcOrder.getOrderId());
                    }
            }
           //结束
        }
    }
}

